package stockXML;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

public class StockXML {

	public static void ecrireXML(Stock stock, String monFichier)
			throws JAXBException {

		JAXBContext jaxbEcriture = JAXBContext.newInstance(Stock.class);
		Marshaller marshaller = jaxbEcriture.createMarshaller();
		File fichier = new File(monFichier);
		marshaller.marshal(stock, fichier);

	}

	public static Stock lireXML(String monFichier) throws JAXBException {
		JAXBContext jaxbLecture = JAXBContext.newInstance(Stock.class);
		Unmarshaller unmarshaller = jaxbLecture.createUnmarshaller();
		File fichier = new File(monFichier);
		Stock listeProd = (Stock) unmarshaller.unmarshal(fichier);
		return listeProd;
	}

	public static void main(String[] args) throws JAXBException {
		// TODO Auto-generated method stub
		/*
		 * Categorie cat = new Categorie(); cat.idcat = "12"; cat.libelleCat =
		 * "Categorie 1"; Fournisseur four = new Fournisseur(); four.idfour = 3;
		 * four.nom = "Fournisseur 1"; four.adresse = "3 bld Salvador Allende";
		 * four.numTel1 = "05.45.68.86.93"; four.numTel2 = "05.45.39.68.84";
		 * Produit prod = new Produit(); prod.idprod = "160"; prod.fournisseur =
		 * four; prod.categorie = cat; prod.marque = "ATI"; prod.modele =
		 * "Radeon";
		 * 
		 * Stock stock = new Stock(); stock.listeProd.add(prod);
		 * 
		 * ecrireXML(stock, "H:/NFA019/stock.xml");
		 */

		Stock listeProd = lireXML("H:/NFA019/stock.xml");
		listeProd.afficherProd();

	}

}
